package cn.four.hqServer.modules.userlogin.utils;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

public class SessionContext {
    private static SessionContext sessionListen;
    private HashMap<String, HttpSession> map;

    private SessionContext(){
        map = new HashMap<String, HttpSession>();
    }

    /**
     * 获取SessionListen对象
     * @return
     */
    public static SessionContext getSessionContext(){
        if(sessionListen == null){
            sessionListen = new SessionContext();
            return sessionListen;
        }
        return sessionListen;
    }

    /**
     * 添加session
     * @param session
     */
    public void addSession(HttpSession session){
        map.put(session.getId(),session);
    }

    /**
     * 获取session
     * @param sid
     * @return
     */
    public HttpSession getSession (String sid){
        return map.get(sid);
    }

    /**
     * 删除session
     * @param sid
     */
    public void delSession(String sid){
        map.remove(sid);
    }
}
